<?php
Design::h1("Vienos paraiškos suadministravimo laikas");
require 'DB/db_data_loader.php';
?>
<div class="data_table">
    <table class="data_table" border="1">
        <tr>
            <td title="Eulutėse: Paramos priemonės. Stulpeliuose: Padaliniai"><b>Priemonės / Padaliniai</b></td>
            <?php
            $subdivisions = get_subdivisios_associative();
            foreach ($subdivisions as $code=>$name) {
                $code = htmlspecialchars($code);
                $name = htmlspecialchars($name);
                echo "<td title='Pdalinio kodas: $code'>$name</td>";
            }
            ?>
        </tr>
        <?php
        $measures = get_support_measures_associative();
        require 'Processing/subdivision_data_processing.php';
        foreach ($measures as $measure_code=>$measure_name) {
            $measure_code = htmlspecialchars($measure_code);
            $measure_name = htmlspecialchars($measure_name);
            echo "<tr><td class=' ' title='Priemonės kodas: $measure_code'>$measure_name</td>";
            $measures = SubdivisionData::get_subdivisions($measure_code);
            foreach ($measures as $subdivision_code=>$time) {
                $subdivision = htmlspecialchars($measures[$subdivision_code]);
                $time = intval($time);
                if ($time) {
                    echo "<td>$time</td>";
                } else {
                    echo "<td>&nbsp;</td>";
                }
            }
            echo '</tr>';
        }
        ?>
    </table>
</div>

<?php
Design::h1("Naudojamos Informacinės sistemos");
?>
<div class="data_table">
    <table class="data_table" border="1">
        <tr>
            <td title="Eulutėse: Informacinės sistemos. Stulpeliuose: Padaliniai"><b>IS / Padaliniai</b></td>
            <?php
            foreach ($subdivisions as $code=>$name) {
                $code = htmlspecialchars($code);
                $name = htmlspecialchars($name);
                echo "<td title='Pdalinio kodas: $code'>$name</td>";
            }
            ?>
        </tr>
        <?php
        $is_names = get_is_associative();
        $subdivisions_is = get_subdivision_is();
        foreach ($is_names as $code=>$is_name) {
            $is_code = htmlspecialchars($code);
            $is_name = htmlspecialchars($is_name);
            echo "<tr><td class=' ' title='Informacinės sistemos kodas: $is_code'>$is_name</td>";
            $subdivisions = SubdivisionData::get_subdivisions($measure_code);
            foreach ($subdivisions as $subdivision_code=>$time) {
                if (array_key_exists($subdivision_code, $subdivisions_is) &&
                array_key_exists($code, $subdivisions_is[$subdivision_code])) {
                    echo "<td>+</td>";
                } else {
                    echo "<td>&nbsp;</td>";
                }
            }
            echo '</tr>';
        }
        ?>
    </table>
</div>

<?php
Design::h1("Gauta paraiškų");
?>
<div class="data_table">
    <table class="data_table" border="1">
        <tr>
            <td title="Eulutėse: Informacinės sistemos. Stulpeliuose: Padaliniai"><b>Priemonė / Laikotarpis</b></td>
            <?php
            $dates = SubdivisionData::get_dates_predicted(0);
            $dates = array_keys($dates);
            foreach ($dates as $date) {
                $date = htmlspecialchars($date);
                echo "<td>$date</td>";
            }
            ?>
        </tr>
        <?php
        $measures = get_support_measures_associative();
        $quantities = SubdivisionData::get_hystorical_quantities($measures, $dates);
        foreach ($measures as $measure_code=>$measure_name) {
            $measure_code = htmlspecialchars($measure_code);
            $measure_name = htmlspecialchars($measure_name);
            echo "<tr><td class=' ' title='Priemonės kodas: $measure_code'>$measure_name</td>";
            foreach ($dates as $value) {
                if (!$quantities[$measure_code][$date]->predicted) {
                    $received = intval($quantities[$measure_code][$date]->sum_received);
                    $administrated = intval($quantities[$measure_code][$date]->sum_administrated);
                    echo '<td>';
                        echo "<span title='Gauta: $received' class='received'>$received</span><br/>";
                        echo "<span title='Suadministruota: $administrated' class='addministrated'>$administrated</span><br/>";
                    echo '</td>';
                } else {
                    echo '<td>&nbsp;</td>';
                }
            }
            echo '</tr>';
        }
        ?>
    </table>
</div>    
Rodoma: gauta paraiškų, suadministruota.